package day03;

/**
 * @author Jetwang
 * @version 1.0
 * @since 2023/3/13 14:24
 * 对称的二叉树
 */
public class Offer28Non {
    public boolean isSymmetric(TreeNode root) {
        if (root == null || (root.left == null && root.right == null)) {
            return true;
        }
        return f(root.left, root.right);
    }

    private boolean f(TreeNode A, TreeNode B) {
        if (A == null && B == null) {
            return true;
        }
        if (A == null || B == null) {
            return false;
        }
        if (A.val != B.val) {
            return false;
        }
        return f(A.left, B.right) && f(A.right, B.left);
    }
}
